<template>
  <div class="content-card">
    <div class="card-header">
      <h2><i class="fas fa-user-edit mr-2"></i>编辑用户</h2>
    </div>
    <div class="card-body">
      <form @submit.prevent="updateUser" class="col-md-6">
        <input type="hidden" v-model="user.id">
        <div class="form-group">
          <label>用户名</label>
          <input type="text" v-model="user.username" class="form-control" required>
        </div>
        <div class="form-group">
          <label>密码</label>
          <input type="password" v-model="user.password" class="form-control" placeholder="留空表示不修改密码">
        </div>
        <div class="form-group">
          <label>角色</label>
          <select v-model="user.role" class="form-control" required>
            <option value="USER">普通用户</option>
            <option value="ADMIN">管理员</option>
          </select>
        </div>
        <div class="mt-4">
          <button type="submit" class="btn btn-primary">
            <i class="fas fa-save mr-1"></i>更新
          </button>
          <router-link to="/user" class="btn btn-secondary">
            <i class="fas fa-arrow-left mr-1"></i>返回
          </router-link>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'UserEdit',
  data() {
    return {
      user: {
        id: null,
        username: '',
        password: '',
        role: ''
      }
    }
  },
  methods: {
    updateUser() {
      // TODO: 实现更新用户的API调用
      console.log('更新用户:', this.user)
      this.$router.push('/user')
    }
  },
  created() {
    // TODO: 实现获取用户详情的API调用
    const userId = this.$route.params.id
    this.user = {
      id: userId,
      username: 'user1',
      role: 'USER'
    }
  }
}
</script>

<style scoped>
/* 卡片样式 */
.content-card {
  margin: 20px;
  border-radius: 15px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  background: linear-gradient(145deg, #ffffff 0%, #f8f9fa 100%);
}

/* 卡片头部样式 */
.card-header {
  background-color: #2c3e50;
  color: white;
  padding: 1.5rem 2rem;
  border-bottom: none;
  border-radius: 15px 15px 0 0;
}

.card-header h2 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.card-header i {
  color: #3498db;
  margin-right: 0.5rem;
  font-size: 1.2rem;
}

/* 表单样式 */
.form-group {
  margin-bottom: 1.75rem;
}

.form-group label {
  font-weight: 500;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  color: #333;
}

.form-control {
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.form-control:focus {
  border-color: #3498db;
  box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
}

/* 选择框样式 */
select.form-control {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M6 8L2 4l1.5-1.5L6 5.25 9.5 1.75 11 3l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 12px 12px;
  padding-right: 2.5rem;
}

/* 角色标签样式 */
.role-tag {
  padding: 0.35rem 0.75rem;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
  margin-bottom: 0.5rem;
}

.role-admin {
  background-color: #3498db;
  color: white;
}

.role-user {
  background-color: #95a5a6;
  color: white;
}

/* 按钮样式 */
.btn {
  padding: 0.85rem 1.75rem;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.btn-primary {
  background-color: #3498db;
  border: none;
}

.btn-primary:hover {
  background-color: #2980b9;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(52, 152, 219, 0.2);
}

.btn-secondary {
  background-color: #6c757d;
  border: none;
}

.btn-secondary:hover {
  background-color: #5a6268;
  transform: translateY(-1px);
}

/* 间距类 */
.mr-2 {
  margin-right: 0.75rem;
}

.mr-1 {
  margin-right: 0.5rem;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .card-header h2 {
    font-size: 1.5rem;
  }
  
  .form-control {
    padding: 0.7rem 0.85rem;
    font-size: 0.9rem;
  }
  
  .btn {
    padding: 0.7rem 1.4rem;
    font-size: 0.9rem;
  }
  
  .form-group {
    margin-bottom: 1.5rem;
  }
}
</style>
